


let http= require("http");

function app(){
        var urls = []; //
        var app = function (req, res) {
           let url = req.url;
           for(let key in urls){
               if(url==key){
                urls[url](req,res);
               }
           }
           res.end();
        }

        /**
         * use方法就是把函数添加到函数数组中---前置控制器
         * @param task
         */
        app.get = function (url,task) {
            urls[url]=task;
        }
        return app;    // 返回实例
}

let a= app();
a.get('/demo.html',function(req,res){
    res.write("this is demo");
 })
a.get('/demo2.html',function(req,res){
    res.write("this is demo2");
 })
http.createServer(a).listen(8080);


